<template>
  <div>
    <div v-if="query.subId === ''|| subNo === '9999'">
      <div class="my-code">点击子项查看对应子项分配</div>
    </div>
    <div v-else>
      <!--工具栏-->
      <div style="margin-bottom: 23px;" class="uifix-tool-header">
        <div class="titleSub uifix-role-span">
          子项分配 - {{ subNo }}
        </div>
      </div>
      <div class="head-container">
        <template>
          <!-- <el-button slot="left" class="filter-item" size="mini" type="warning" icon="el-icon-location-information" @click="resourceSynchronization()">资源同步</el-button> -->
          <el-button slot="left" class="filter-item" size="mini" type="primary" icon="el-icon-plus" @click="addResource">添加资源</el-button>
          <!-- 点击子项 接口返回无数据时显示该按钮 -->
          <el-button slot="left" class="filter-item" size="mini" type="plain" icon="el-icon-arrow-down" :disabled="isResourceInit" @click="openDialog()">资源初始化</el-button>
          <!-- 点击子项 操作列为启用禁用时显示该按钮 -->
          <el-button slot="left" class="filter-item" size="mini" icon="el-icon-document-copy" :disabled="checkedRowList.length >0 ? false : true" @click="copyResource()">复制资源</el-button>
        </template>
      </div>
      <!-- 资源初始化 -->
      <el-dialog title="资源初始化" :visible.sync="resourceDialog" :destroy-on-close="false" convert-record :append-to-body="true" :close-on-click-modal="false" width="720px">
        <el-form ref="resourceInitForm" size="small" label-width="80px" :rules="rules" :model="resourceInitForm" :inline="true">
          <el-form-item label="方式" prop="manner">
            <el-col :span="24">
              <el-radio-group v-model="resourceInitForm.manner" style="margin-top: 9px;">
                <el-radio label="0">资源创建</el-radio>
                <el-radio label="1">批量添加资源</el-radio>
                <el-radio label="2">继承资源</el-radio>
              </el-radio-group>
            </el-col>
          </el-form-item>
          <br>
          <el-tag v-if="resourceInitForm.manner === '0'">注：依据当前项目的"人力资源"功能,将"项目成员"及其"项目内专业"、"项目角色"进行自动组合并转化为子项分配。<br>例如：建筑-设计人-小明（用户名）、暖通-设计人-小军（用户名）、室内-设计人-小明（用户名）</el-tag>
          <el-form-item v-if="resourceInitForm.manner === '1'" key="disciplines" label="专业" prop="disciplines">
            <el-col :span="24">
              <el-select v-model="resourceInitForm.disciplines" multiple filterable placeholder="请选择" class="text-width1">
                <el-option
                  v-for="item in projectDisciplineList"
                  :key="item.id"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-col>
          </el-form-item>
          <el-form-item v-if="resourceInitForm.manner === '2'" label="项目">
            <el-col :span="24" style="margin-top: 6px;">{{ projectName }}</el-col>
          </el-form-item>
          <el-form-item v-if="resourceInitForm.manner === '2'" key="sourceSubId" label="子项" prop="sourceSubId">
            <el-col :span="24">
              <el-select v-model="resourceInitForm.sourceSubId" class="text-width1" filterable placeholder="请选择">
                <el-option v-for="item in subList" :key="item.subId" :label="item.subNo+ '-' +item.subName" :value="item.subId" />
              </el-select>
            </el-col>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogClose">取消</el-button>
          <el-button type="primary" :loading="isLoading" @click="submitResource">确认</el-button>
        </div>
      </el-dialog>
      <!--表单组件-->
      <el-form ref="form" :inline="true" :model="form" size="small" label-width="85px">
        <!-- 分配人数=激活人数（默认新增的也算激活） -->
        <!-- 禁用人数=总人数-激活人数（默认新增的也算激活） -->
        <span style="float: right;margin-top: -42px;">分配人数 <span v-if="isHasEnabled===true" style="margin-right: 5px">{{ activeNum }}</span>
          <span v-else>{{ form.projectMembers.length }}</span>
          <!-- 小眼睛 -->
          <span v-if="isHasEnabled === true&&form.projectMembers.length-activeNum>0" style="cursor: pointer;margin-left: 10px">
            <el-tooltip slot="right" effect="dark" placement="top-start" content="显示禁用人员">
              <svg-icon v-show="membersFontShow" icon-class="hide-p" @click="showProjectMembers" />
            </el-tooltip>
            <el-tooltip slot="right" effect="dark" placement="top-start" content="隐藏禁用人员">
              <svg-icon v-show="!membersFontShow" icon-class="show-p" @click="hideProjectMembers" />
            </el-tooltip>{{ form.projectMembers.length-activeNum }}</span>
        </span>
        <!--表格渲染-->
        <div class="my_table">
          <el-table ref="table" height="calc(100vh - 360px)" :data="form.projectMembers" style="width: 100%;" class="projectMembers" @selection-change="crud.selectionChangeHandler">
            <el-table-column width="55">
              <template slot-scope="scope">
                <span v-show="scope.row.show">
                  <el-checkbox v-model="scope.row.checked" :disabled="!scope.row.memberId|| scope.row.enabled === false" @change="changeCheckbox($event,scope.$index,scope.row)" />
                </span>
              </template>
            </el-table-column>
            <el-table-column label="项目内专业">
              <template slot-scope="scope">
                <span v-show="scope.row.show">
                  <el-form-item
                    :key="scope.$index"
                    :prop="'projectMembers.' + scope.$index + '.discipline'"
                    :rules="[{required: scope.row.isValidatediscipline == true ? true : false,message:'项目内专业不能为空',trigger: 'change'}]"
                  >
                    <el-select v-model="scope.row.discipline" v-viewinput="scope.row.memberId!=null" clearable filterable placeholder="" :disabled="scope.row.memberId!=null" @change="changeDiscipline(scope.row)">
                      <el-option
                        v-for="item in projectDisciplineList"
                        :key="item.id"
                        :label="item.label"
                        :value="item.value"
                      />
                    </el-select>
                  </el-form-item>
                </span>
              </template>
            </el-table-column>
            <el-table-column label="项目角色">
              <template slot-scope="scope">
                <span v-show="scope.row.show">
                  <el-form-item
                    :key="scope.$index"
                    :prop="'projectMembers.' + scope.$index + '.projRoleId'"
                    :rules="[{
                      required: true, message: '项目角色不能为空', trigger: 'change'
                    }]"
                  >
                    <el-select v-model="scope.row.projRoleId" v-viewinput="scope.row.memberId!=null" filterable placeholder="" :disabled="scope.row.memberId!=null" @change="changeRole(scope.row)">
                      <el-option
                        v-for="item in projRoleIdList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                      />
                    </el-select>
                  </el-form-item>
                </span>
              </template>
            </el-table-column>
            <el-table-column label="人员">
              <template slot-scope="scope">
                <span v-show="scope.row.show">
                  <el-form-item
                    :key="scope.$index"
                    :prop="'projectMembers.' + scope.$index + '.userId'"
                    :rules="[{
                      required: true, message: '人员不能为空', trigger: 'change'
                    }]"
                  >
                    <el-select v-model="scope.row.userId" v-viewinput="scope.row.memberId!=null" filterable placeholder="" :disabled="scope.row.memberId!=null" @change="changeProjectMembers(scope.row)">
                      <el-option v-for="item in (scope.row.memberId!=null ? projResourceList:scope.row.projResourceList)" :key="item.user.id" :value="item.user.id" :label="item.user.nickName+'（'+item.user.username+'）'" :disabled="item.status === 0 ? true : false" />
                    </el-select>
                  </el-form-item>
                </span>
              </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" label="勋章" width="50">
              <template slot-scope="scope">
                <el-tooltip v-show="scope.row.show" class="item" effect="dark" placement="top">
                  <div slot="content" style="display: flex;gap: 4px;">
                    <p v-for="(item,key) in scope.row.medalConfigDtos" :key="key">{{ item.name }}</p>
                  </div>
                  <span style="cursor: pointer;">{{ scope?.row?.medalConfigDtos?.length || "" }}</span>
                </el-tooltip>
              </template>
            </el-table-column>
            <!-- 当memberId有值时显示启用禁用 否则就是新增显示删除 -->
            <el-table-column label="操作" width="80px">
              <template slot-scope="scope">
                <el-tooltip v-if="scope.row.memberId!=null" v-show="scope.row.show" slot="right" effect="dark" :content="scope.row.enabled?'禁用':'激活'" placement="top-start">
                  <el-switch
                    v-model="scope.row.enabled"
                    :width="30"
                    @change="scope.row.enabled===!scope.row.enabled; scope.row.enabled ? activeNum++ :activeNum--"
                  />
                </el-tooltip>
                <el-button v-else v-show="scope.row.show" slot="reference" class="uifix-table-action-error-btn" style="margin-bottom: 8px;margin-left: 8px;padding: 0" type="text" size="mini" icon="el-icon-delete" @click="handleDelete(scope.row,scope.$index)" />
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="header-action" style="float: right;margin-top: 20px;">
          <el-button type="plain" @click="cancelCU">取消</el-button>
          <el-popover
            v-if="isHasEnabled===true"
            ref="sure"
            placement="top"
            width="200"
          >
            <p>温馨提示：一旦提交,内容便不可修改，请确认无误后提交！</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs['sure'].doClose()">取消</el-button>
              <el-button type="primary" size="mini" @click="submitCrudForm">确定</el-button>
            </div>
            <el-button slot="reference" :loading="crud.status.cu === 2" type="primary">确认</el-button>
          </el-popover>
          <el-button v-else slot="reference" :loading="crud.status.cu === 2" type="primary" @click="submitCrudForm">确认</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>
<script>
import crudprojectMember, { add, getProjectMemberData, initProjectMember, inheritProjectMember, batchProjectMember } from '@/api/project/projectMember'
import { projectDiscipline } from '@/api/project/projectSub'
import { getProjectRole, getProjectResource } from '@/api/project/humanRes'
import CRUD, { presenter, header, form } from '@brotherCrud/crud'
import { setLoading } from '../../../utils'
import { mapGetters } from 'vuex'
import { iconMap } from '@/views/system/medal/config'

const defaultForm = { projectMembers: [] }
export default {
  cruds() {
    return [
      CRUD({ title: '项目成员', url: 'api/projectMember', idField: 'subId', query: { subId: '', page: 0, size: 10000 }, sort: ['discipline,asc', 'projRoleId,asc'], crudMethod: { ...crudprojectMember },
        queryOnPresenterCreated: false
      })
    ]
  },
  mixins: [presenter(), header(), form(defaultForm)],
  props: {
    projId: {
      type: Number,
      default: 0
    },
    subNo: {
      type: String,
      default: ''
    },
    projectSubList: {
      type: Array,
      default: () => { return [] }
    },
    getdetail: {
      type: Function,
      default: null
    }
  },
  data() {
    this.setLoading = setLoading.bind(this)
    return {
      emptyRoleNameList: ['施工管理', '项目审阅人', '外部审阅人'], // 项目内专业可为空的角色
      checkedRowList: [], // 选中的行
      isHasEnabled: true, // 判断操作列是启用还是删除
      subList: [], // 子项下拉框
      subId: null,
      disciplineDatas: [], // 专业多选变量
      isLoading: false, // 按钮加载状态
      resourceDialog: false,
      resourceInitForm: {
        manner: '0',
        disciplines: [],
        sourceSubId: ''
      }, // 资源初始化
      projectName: '',
      userDeptName: '',
      userDeptId: null,
      projectDisciplineList: [], // 项目内专业
      projRoleIdList: [], // 项目角色
      projResourceList: [], // 项目人力资源池
      isResourceInit: false, // 显示资源初始化
      membersFontShow: true, // 显示‘显示’
      activeNum: 0, // 激活人员个数
      rules: {
        sourceSubId: [
          { required: true, message: '子项不能为空', trigger: 'change' }
        ],
        disciplines: [
          { required: true, message: '专业不能为空', trigger: 'change' }
        ]
      },
      iconMap
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ])
  },
  mounted() {
    this.userDeptId = this.user.dept.id
    this.userDeptName = this.user.dept.name
    this.hanleProjRole(this.projId)
    this.hanleProjResource(this.projId)
  },
  methods: {
    /* 资源同步 */
    resourceSynchronization() {
      // const params = {
      //   id: this.user.id
      // }
      // userDesktopDetail(params).then(data => {
      //   if (data) {
      //     this.crud.notify(this.projectName + '，子项资源同步已完成，请查阅', CRUD.NOTIFICATION_TYPE.SUCCESS)
      //     this.crud.resetQuery()
      //   }
      // })
    },
    /* 资源初始化 */
    // 过滤子项下拉框
    getSub: function() {
      // 过滤子项号为'9999'以及当前子项
      const filtersList = this.projectSubList.filter(element => element.subId !== this.subId && element.subNo !== '9999')
      this.subList = filtersList
    },
    // 打开弹框
    openDialog() {
      this.getSub()
      this.clearResourceInit()
      this.resourceDialog = true
    },
    // 清空弹框
    clearResourceInit() {
      this.resourceInitForm.sourceSubId = ''
      this.resourceInitForm.disciplines = []
      this.resourceInitForm.manner = '0'
    },
    // 提交资源初始化
    submitResource() {
      this.$refs.resourceInitForm.validate(valid => {
        if (valid) {
          if (this.isLoading) return
          this.setLoading(true)
          if (this.resourceInitForm.manner === '0') {
            // 资源初始化
            const params = {
              projId: this.projId,
              subId: this.subId
            }
            initProjectMember(params).then(res => {
              this.$notify({
                title: '资源创建成功',
                type: 'success',
                duration: 2500
              })
              this.setLoading(false)
              // 当接口返回没有数据时 可以点击资源初始化
              this.form.projectMembers = this.form.projectMembers.concat(res)
              this.form.projectMembers.map(row => {
                this.multiFilter(row)
              })
              // 隐藏禁用子项人员
              this.hideProjectMembers()
              this.clearResourceInit()
              this.dialogClose()
            }).catch(err => {
              console.log(err.response.data.message)
            })
          } else if (this.resourceInitForm.manner === '1') {
            // 批量添加资源
            const params = {
              disciplines: this.resourceInitForm.disciplines,
              projId: this.projId,
              subId: this.subId
            }
            batchProjectMember(params).then(res => {
              this.$notify({
                title: '批量添加资源成功',
                type: 'success',
                duration: 2500
              })
              this.setLoading(false)
              this.form.projectMembers = this.form.projectMembers.concat(res)
              this.form.projectMembers.map(row => {
                this.multiFilter(row)
              })
              // 隐藏禁用子项人员
              this.hideProjectMembers()
              this.clearResourceInit()
              this.dialogClose()
            }).catch(err => {
              console.log(err.response.data.message)
            })
          } else if (this.resourceInitForm.manner === '2') {
            // 继承资源
            const params = {
              currentSubId: this.subId,
              sourceSubId: this.resourceInitForm.sourceSubId
            }
            inheritProjectMember(params).then(res => {
              this.$notify({
                title: '继承资源成功',
                type: 'success',
                duration: 2500
              })
              this.setLoading(false)
              this.form.projectMembers = this.form.projectMembers.concat(res)
              this.form.projectMembers.map(row => {
                this.multiFilter(row)
              })
              // 隐藏禁用子项人员
              this.hideProjectMembers()
              this.clearResourceInit()
              this.dialogClose()
            }).catch(err => {
              console.log(err.response.data.message)
            })
          }
        } else {
          return false
        }
      })
    },
    // 关闭弹框
    dialogClose() {
      this.clearResourceInit()
      this.resourceDialog = false
    },
    /* 添加资源 */
    // 批量新增
    addResource() {
      let list = {}
      list = {
        userId: null,
        discipline: '',
        projRoleId: '',
        memberId: null, // 新增数据无menmberId
        projectSub: { subId: this.subId },
        show: true, // 点击眼睛 禁用状态的数据显示隐藏
        enabled: true // 启用
      }
      this.form.projectMembers.push(list)
      this.activeNum++// 人数加1

      // 触发表格滚动到底部
      this.$nextTick(() => {
        const tableBodyWrapper = this.$refs.table.bodyWrapper
        tableBodyWrapper.scrollTop = tableBodyWrapper.scrollHeight
      })
    },
    /* 子项分配 */
    // 获取表格数据
    hanleProjectMember(subId) {
      const params = {
        subId: subId,
        sort: ['discipline,asc', 'projRoleId,asc'],
        page: 0,
        size: 10000
      }
      getProjectMemberData(params).then(data => {
        if (data) {
          // 当接口返回没有数据时 可以点击资源初始化
          if (data.content.length > 0) {
            this.isResourceInit = true
            this.isHasEnabled = true
          } else {
            this.isResourceInit = false
            this.isHasEnabled = false
          }
          // 清空表格
          this.form.projectMembers = []
          this.form.projectMembers = this.form.projectMembers.concat(data.content)
          // 隐藏禁用子项人员
          this.hideProjectMembers()
        }
      })
    },
    // 显示禁用人员
    showProjectMembers() {
      this.form.projectMembers.map(i => {
        if (!i.show) {
          i.show = true
        }
      })
      this.membersFontShow = false// 显示‘隐藏’
      this.form.projectMembers.reverse().reverse()
    },
    // 隐藏禁用子项人员
    hideProjectMembers() {
      let num = 0
      this.form.projectMembers.map(i => {
        if (i.enabled) {
          i.show = true
          num++
        } else {
          i.show = false
        }
      })
      this.activeNum = num
      this.membersFontShow = true// 显示‘显示’
      this.form.projectMembers.reverse().reverse()
    },
    // 获取项目内专业
    getProjectDiscipline(subId) {
      const params = {
        subId: subId
      }
      projectDiscipline(params).then(data => {
        if (data) {
          this.projectDisciplineList = data
        }
      })
    },
    // 获取项目角色
    hanleProjRole(projId) {
      const params = {
        projId: projId,
        noManager: true
      }
      getProjectRole(params).then(data => {
        if (data) {
          this.projRoleIdList = data
        }
      })
    },
    // 切换项目内专业
    changeDiscipline(row) {
      row.userId = ''
      this.multiFilter(row)
      this.removeDuplicate()
    },
    // 切换项目内角色
    changeRole(row) {
      row.userId = ''
      this.multiFilter(row)
      // 切换项目内角色 当角色为“施工管理、项目审阅人、外部审阅人”时 项目内专业可以为空 反之不能为空
      if (this.emptyRoleNameList.includes(this.projRoleIdList.find(item => { return item.id === row.projRoleId }).name)) {
        // 不必填
        this.$set(row, 'isValidatediscipline', false)
      } else {
        // 必填
        this.$set(row, 'isValidatediscipline', true)
      }
      this.removeDuplicate()
    },
    // 切换成员
    changeProjectMembers() {
      this.removeDuplicate()
    },
    // 成员去重处理
    removeDuplicate() {
      for (let i = 0; i < this.form.projectMembers.length - 1; i++) {
        for (let j = i + 1; j < this.form.projectMembers.length; j++) {
          if (this.form.projectMembers[i].discipline === this.form.projectMembers[j].discipline && this.form.projectMembers[i].projRoleId === this.form.projectMembers[j].projRoleId && this.form.projectMembers[i].userId === this.form.projectMembers[j].userId) {
            let discipline = ''
            let projRoleId = ''
            let userId = ''
            this.projectDisciplineList.map(item => {
              if (item.value === this.form.projectMembers[i].discipline) {
                discipline = item.label
              }
            })
            this.projRoleIdList.map(item => {
              if (item.id === this.form.projectMembers[i].projRoleId) {
                projRoleId = item.name
              }
            })
            this.projResourceList.map(item => {
              if (item.user.id === this.form.projectMembers[i].userId) {
                userId = item.user.nickName
              }
            })
            this.crud.notify(discipline + '专业-' + projRoleId + '角色-' + userId + '用户存在重复分配，请检查。', CRUD.NOTIFICATION_TYPE.ERROR)
            this.form.projectMembers[j].projRoleId = null
            this.form.projectMembers[j].discipline = null
            this.form.projectMembers[j].userId = null
            return false
          }
        }
      }
    },
    // 根据项目内专业+项目角色多元素筛选
    multiFilter(row) {
      const filtersList = this.projResourceList.filter(function(item) {
        if (row.discipline === '' && row.projRoleId !== '') {
          // 专业为空，角色不为空
          if (item.roles.length > 0 && item.roles.find(element => element.id === row.projRoleId)) {
            return item
          }
        } else if (row.discipline !== '' && row.projRoleId === '') {
          // 专业不为空，角色为空
          if (item.projectDiscipline !== undefined && JSON.parse(item.projectDiscipline).find(element => element.id === row.discipline)) {
            return item
          }
        } else {
          // 专业不为空，角色不为空
          if ((item.roles.length > 0 && item.roles.find(element => element.id === row.projRoleId)) && (item.projectDiscipline !== undefined && JSON.parse(item.projectDiscipline).find(element => element.id === row.discipline))) {
            return item
          }
        }
      })
      this.$set(row, 'projResourceList', filtersList)
      // 当项目内专业和项目角色都不为空时 人员只有一个且该条为启用状态时 默认选中
      if (row.projResourceList.length === 1 && row.projResourceList[0].status !== 0) {
        row.userId = row.projResourceList[0].user.id
      }
    },
    // 获取项目人力资源池
    hanleProjResource(projId) {
      const params = {
        projId: projId
      }
      getProjectResource(params).then(data => {
        if (data) {
          this.projResourceList = data.content
        }
      })
    },
    // 删除
    handleDelete(row, index) {
      this.activeNum--
      this.form.projectMembers.splice(index, 1)
    },
    /* 确认提交*/
    submitCrudForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          // 分配的专业与子项中的涉及专业需一对一
          const projectMemberTemp = []
          // 去重
          const obj = {}
          this.form.projectMembers.reduce(function(item, next) {
            obj[next.discipline] ? '' : obj[next.discipline] = true && item.push(next)
            return item
          }, []).map(function(item2) {
            projectMemberTemp.push({ id: item2.discipline })
          })
          let disUer = false
          for (let i = 0; i < this.form.projectMembers.length - 1; i++) {
            for (let j = i + 1; j < this.form.projectMembers.length; j++) {
              if (this.form.projectMembers[i].discipline === this.form.projectMembers[j].discipline && this.form.projectMembers[i].projRoleId === this.form.projectMembers[j].projRoleId && this.form.projectMembers[i].userId === this.form.projectMembers[j].userId) {
                disUer = true
                let discipline = ''
                let projRoleId = ''
                let userId = ''
                this.projectDisciplineList.map(item => {
                  if (item.value === this.form.projectMembers[i].discipline) {
                    discipline = item.label
                  }
                })
                this.projRoleIdList.map(item => {
                  if (item.id === this.form.projectMembers[i].projRoleId) {
                    projRoleId = item.name
                  }
                })
                this.projResourceList.map(item => {
                  if (item.user.id === this.form.projectMembers[i].userId) {
                    userId = item.user.nickName
                  }
                })
                this.crud.notify(discipline + '专业-' + projRoleId + '角色-' + userId + '用户存在重复分配，请检查。', CRUD.NOTIFICATION_TYPE.ERROR)
                return false
              }
            }
          }
          if (!disUer) {
            add(this.form.projectMembers)
              .then(res => {
                this.$notify({
                  title: '保存成功',
                  type: 'success',
                  duration: 2500
                })
                this.hanleProjectMember(this.subId)
                this.getdetail(this.subId)
                this.$refs['sure'].doClose()
              })
              .catch(err => {
                console.log(err.response.data.message)
              })
            return true
          } else {
            return false
          }
        }
      })
    },
    // 多选
    changeCheckbox(val, rowIndex, row) {
      // 处理选中信息
      if (val === true) {
        // 赋值当前行
        const currentRow = {
          index: rowIndex,
          userId: null,
          discipline: row.discipline,
          projRoleId: row.projRoleId,
          memberId: null, // 新增数据无menmberId
          projectSub: { subId: row.projectSub.subId },
          show: true, // 点击眼睛 禁用状态的数据显示隐藏
          enabled: true // 启用
        }
        this.checkedRowList.push(currentRow)
      } else {
        const deleteIndex = this.checkedRowList.findIndex(item => {
          if (item.index === rowIndex) {
            return true
          }
        })
        this.checkedRowList.splice(deleteIndex, 1)
      }
    },
    // 复制资源
    copyResource() {
      this.form.projectMembers = this.form.projectMembers.concat(this.checkedRowList)
      this.form.projectMembers.map(row => {
        this.multiFilter(row)
      })
      // 隐藏禁用子项人员
      this.hideProjectMembers()
      // 触发表格滚动到底部
      this.$nextTick(() => {
        const tableBodyWrapper = this.$refs.table.bodyWrapper
        tableBodyWrapper.scrollTop = tableBodyWrapper.scrollHeight
      })
    },
    // 取消
    cancelCU() {
      // 清空复制数组
      this.checkedRowList = []
      this.form.projectMembers = []
      this.hanleProjectMember(this.subId)
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .titleSub{
    height: 26px;
    line-height: 26px;
    margin-top: 9px;
  }
  ::v-deep .el-input-number .el-input__inner {
    text-align: left;
  }
  ::v-deep .el-form-item--small .el-form-item__content {
    line-height: 18px;
  }
  .text-width1{
    width: 536px
  }
  .text-width2{
    width: 218px
  }
  ::v-deep .el-table .cell{
    overflow: inherit;
  }
  ::v-deep .el-table__body-wrapper {
    overflow-y: auto;
    margin-top: 2px;
    height: 728px;
  }
  .el-tag {
    height: auto;
    margin-left: 37px;
  }
  ::v-deep .projectMembers.el-table--small {
    .el-table__cell{
      padding: 0 0;
    }
    .el-form-item{
      margin-top: 6px;
      margin-bottom: 9px;
    }
  }
  ::v-deep .projectMembers.el-table td.el-table__cell {
    border-bottom: 0!important;
    .el-switch{
      margin-top: -8px;
    }
    .el-checkbox__input{
      margin-top: -3px;
    }
  }
</style>
